layui.use(['form','layer','laydate','table','laytpl','layedit'],function(){
    var form = layui.form,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        layedit = layui.layedit,
        table = layui.table;
        username = localStorage.getItem("username"); 
    //学生预报名审核列表
    var tableIns = table.render({
		  elem: '#registrationInformation',
          url: 'http://127.0.0.1:8000/registrationInformationlist?user='+username,
          cellMinWidth: 95,
          page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
              layout: ['prev', 'page', 'next', 'skip', 'limit', 'count'] //自定义分页布局
              //,curr: 5 //设定初始在第 5 页
              , limit: 10//一页显示多少条
              , limits: [10, 15, 20, 25]//每页条数的选择项
              , groups: 5//只显示 2 个连续页码
              // ,first: "首页" //不显示首页
              // ,last: "尾页" //不显示尾页
          },
          //toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
          defaultToolbar: ['filter', 'exports', 'print'],
          //limit : 20,
          //limits : [10,15,20,25],
          id: "examine",
          cols: [[
              { type: "checkbox", fixed: "left", width: 50 },
              {field: 'userNumber', title: '学号', width:170},
              {field: 'realName', title: '姓名', width:150},
              {field: 'userHobby',title: '课程',align: 'center',width: 170}, 
              {field: 'userSex', title: '性别',  align:'center',width:130},
              {field: 'Teacher', title: '老师',  align:'center',width:130},
              { title: '操作', width: 130, templet: '#registrationInformationBar', fixed: "right", align: "center", width:250}
          ]],
          done: function (res, curr, count) {
              //图片放大预览
              var ids;
              for (var j in res.data) {
                  ids = res.data[j].newsId;
                  layer.photos({
                      photos: '.thumbnailImages' + ids
                  });
              }
  
          }
    });
 //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
 $(".search_btn").on("click",function(){
    if($(".searchVal").val() != ''){
        table.reload("registrationInformation",{
            page: {
                curr: 1 //重新从第 1 页开始
            },
            where: {
                key: $(".searchVal").val()  //搜索的关键字
            }
        })
    }else{
        layer.msg("请输入搜索的内容");
    }
});
    //批量删除
    $(".delAll_btn").click(function(){
        var checkStatus = table.checkStatus('registrationInformation'),
            data = checkStatus.data,
            newsId = [];
        if(data.length > 0) {
            for (var i in data) {
                newsId.push(data[i].examineid);
            }
            layer.confirm('确定选中取消报名？', {icon: 3, title: '提示信息'}, function (index) {
                $.ajax({
                    url: "http://127.0.0.1:8000/allexamineDel",
                    data: { allId: newsId },//将需要删除的releaseId作为参数传入
                    type: "post",
                    dataType: "JSON",
                    success: function (res) {
                        tableIns.reload();
                        layer.close(index);
                        console.log(data.msg)
                    },
                    error: function (res) {

                    }
                })
            })
        }else{
            layer.msg("请选择需要取消的报名？");
        }
    })

    //报名详情
    function registrationInformationDetail(edit){
        var index = layui.layer.open({
            title : "报名详情",
            type : 2,
			area: ['90%', '90%'],
			fixed: false, //不固定
			maxmin: true,
            content : "registrationInformationDetail.html",
            success : function(layero, index){
                var body = layui.layer.getChildFrame('body', index);
                if(edit){
                    body.find(".realName").val(edit.realName);
                    body.find(".userNumber").val(edit.userNumber);
                    body.find(".userSex").attr("src",edit.userSex);
                    body.find(".userPhone").val(edit.userPhone);
                    body.find(".userBirthday").val(edit.userBirthday);
                    body.find(".userEmail").val(edit.userEmail);
                    body.find(".myself").val(edit.myself);
                    body.find(".Class").val(edit.userHobby);
                    body.find(".ClassNumber").val(edit.CourseCode);
                    body.find(".Teacher").val(edit.Teacher);
                    // body.find(".openness input[name='openness'][title='"+edit.newsLook+"']").prop("checked","checked");
                    // body.find(".newsTop input[name='newsTop']").prop("checked",edit.newsTop);
                    form.render();
                }
                setTimeout(function(){
                    layui.layer.tips('点击此处返回文章列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                },500)
            }
        })
    }
     //列表操作
     table.on('tool(registrationInformation)', function(obj){
        var layEvent = obj.event,
            data = obj.data;
			console.log(obj)
        if(layEvent === 'detail'){ //编辑
            registrationInformationDetail(data);
        } else if(layEvent === 'del'){ //删除
            layer.confirm('确定取消报名？',{icon:3, title:'提示信息'},function(index){
                $.get("http://127.0.0.1:8000/examinedel", {
                    examineId: data.examineid  //将需要删除的releaseId作为参数传入
                }, function (data) {
                    tableIns.reload();
                    layer.close(index);
                    layer.msg(data.msg);
                })
            });
        } 
    });

})